import { requestPost } from '../../assets/js/request.js';
import Notify from '@vant/weapp/notify/notify';
Page({
  formSubmit: function (e) {
    wx.showLoading({
      title: '正在登录',
      mask: true,
    })
    let reqData = {
      uname: e.detail.value.uname,
      pwd: e.detail.value.pwd,
      status: this.data.radio
    }
    requestPost('/login.php', reqData)
      .then((res)=>{
        if (res.data == 'ok') {
          wx.showToast({
            title: '登录成功',
            icon:'success'
          })
          setTimeout(function () {
            wx.navigateBack({
              delta: 1
            })
          }, 1500)
          wx.setStorage({
            key: 'uid',
            data: e.detail.value.uname
          })
          wx.setStorageSync('status', this.data.radio)
        }else{
          Notify({ type: 'danger', message: '登录失败,请检测用户名或密码是否正确' });
        }
      })
      .catch((err)=>{
        Notify({ type: 'danger', message: '服务器繁忙，请稍后再试' });
      })
  },
  onChange(event) {
    this.setData({
      radio: event.detail
    });
  },
  
  data: {
    radio:'student'
  },

})